/**
 * 
 */
package action.student;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.opensymphony.xwork2.ActionSupport;

import model.*;


/** 
 * @作者 Zouzr 
 * @创建日期 Dec 19, 2008 
 * @版本 V 1.0 
 */

public class StudentAction extends ActionSupport
{
	
	private List<Object> objects = new ArrayList<Object>();
    
    private List<Student> students = new ArrayList<Student>();//存放所有student记录
    
    private List<Special> specials = new ArrayList<Special>();//存放student对应的special记录
    
    private List<Department> departments = new ArrayList<Department>();//存放Student对应的department记录
    
    
    private List<Studentcourse> studentcourses = new ArrayList<Studentcourse>();
    
    private List<Course> courses = new ArrayList<Course>();
    
    private List<Coursetype> coursetypes = new ArrayList<Coursetype>();
    
    private List<Teacher> teachers = new ArrayList<Teacher>();
    
    
    private List<Score> scores = new ArrayList<Score>();
    
    private ServletActionContext context;
	/**
	 * 获得该学生的基本信息
	 */
	public String getStudentInfoById()
	{
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentDAO Studentdao = (StudentDAO)context.getBean("StudentDAOProxy");
        List temp_Students = Studentdao.getStudentById((String)this.context.getRequest().getSession().getAttribute("stuId"));
       
        for(int i=0;i<temp_Students.size();i++)
        {
        	
        	Object[] obj = (Object[])temp_Students.get(i);
        	Student s = new Student();
        	s = (Student)obj[0];
        	Special sp = new Special();
        	sp = (Special)obj[1];
        	Department d = new Department();
        	d = (Department)obj[2];
        		objects.add(obj);
        		students.add(s);
        		specials.add(sp);
        		departments.add(d);
        	obj = null;
        	s = null;
        	sp = null;
        	d = null;
        }
        return SUCCESS;
	}
	
	/**
	 * 获得该学生的选课信息
	 */
	public String getStudentcourseBystuId()
	{
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentcourseDAO studentcoursedao = (StudentcourseDAO)context.getBean("StudentcourseDAOProxy");
        List temp_Students = studentcoursedao.getStudentcourseInfoByStudentId((String)this.context.getRequest().getSession().getAttribute("stuId"));
        for(int i=0;i<temp_Students.size();i++)
        {
        	
        	Object[] obj = (Object[])temp_Students.get(i);
        	Studentcourse stco = new Studentcourse();
        	stco = (Studentcourse)obj[0];
        	Course co = new Course();
        	co = (Course)obj[2];
        	Teacher te =new Teacher();
        	te = (Teacher)obj[3];
        	Coursetype coty = new Coursetype();
        	coty = (Coursetype)obj[6];
        	
        		objects.add(obj);
        		studentcourses.add(stco);
        		courses.add(co);
        		teachers.add(te);
        		coursetypes.add(coty);
        	
        	obj = null;
        	stco = null;
        	co = null;
        	te = null;
        	coty = null;
        }
        return SUCCESS;
	}
	
	/**
	 * 获得该学生的成绩信息
	 */
	public String getScoreBystuId()
	{
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        ScoreDAO scoredao = (ScoreDAO)context.getBean("ScoreDAOProxy");
        List temp_Students = scoredao.getScoreBystuId((String)this.context.getRequest().getSession().getAttribute("stuId"));
        for(int i=0;i<temp_Students.size();i++)
        {
        	Object[] obj=(Object[])temp_Students.get(i);
        		objects.add(obj);
        		Score sc = (Score)obj[0];
            	Studentcourse stco = (Studentcourse)obj[1];
            	Student st = (Student)obj[2];
            	Course co = (Course)obj[3];
            	Teacher te = (Teacher)obj[4];
            	Special sp = (Special)obj[5];
            	Department de = (Department)obj[6];
            	Coursetype coty = (Coursetype)obj[7];
            	scores.add(sc);
            	studentcourses.add(stco);
            	students.add(st);
            	courses.add(co);
            	teachers.add(te);
            	specials.add(sp);
            	departments.add(de);
            	coursetypes.add(coty);
            	obj=null;
        }
    	return SUCCESS;
	}

	/**
	 * @return the objects
	 */
	public List<Object> getObjects() {
		return objects;
	}

	/**
	 * @param objects the objects to set
	 */
	public void setObjects(List<Object> objects) {
		this.objects = objects;
	}

	/**
	 * @return the students
	 */
	public List<Student> getStudents() {
		return students;
	}

	/**
	 * @param students the students to set
	 */
	public void setStudents(List<Student> students) {
		this.students = students;
	}

	/**
	 * @return the specials
	 */
	public List<Special> getSpecials() {
		return specials;
	}

	/**
	 * @param specials the specials to set
	 */
	public void setSpecials(List<Special> specials) {
		this.specials = specials;
	}

	/**
	 * @return the departments
	 */
	public List<Department> getDepartments() {
		return departments;
	}

	/**
	 * @param departments the departments to set
	 */
	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}

	/**
	 * @return the studentcourses
	 */
	public List<Studentcourse> getStudentcourses() {
		return studentcourses;
	}

	/**
	 * @param studentcourses the studentcourses to set
	 */
	public void setStudentcourses(List<Studentcourse> studentcourses) {
		this.studentcourses = studentcourses;
	}

	/**
	 * @return the courses
	 */
	public List<Course> getCourses() {
		return courses;
	}

	/**
	 * @param courses the courses to set
	 */
	public void setCourses(List<Course> courses) {
		this.courses = courses;
	}

	/**
	 * @return the coursetypes
	 */
	public List<Coursetype> getCoursetypes() {
		return coursetypes;
	}

	/**
	 * @param coursetypes the coursetypes to set
	 */
	public void setCoursetypes(List<Coursetype> coursetypes) {
		this.coursetypes = coursetypes;
	}

	/**
	 * @return the teachers
	 */
	public List<Teacher> getTeachers() {
		return teachers;
	}

	/**
	 * @param teachers the teachers to set
	 */
	public void setTeachers(List<Teacher> teachers) {
		this.teachers = teachers;
	}

	/**
	 * @return the scores
	 */
	public List<Score> getScores() {
		return scores;
	}

	/**
	 * @param scores the scores to set
	 */
	public void setScores(List<Score> scores) {
		this.scores = scores;
	}
}
